<script type="text/javascript" language="JavaScript">
	$(document).ready(function() {
		$( "#portfolio_form" ).dialog({
			title: "<{$smarty.const._MD_PORTFOLIO_ADD_CONTACT}>",
        	autoOpen: false,
        	height: 400,
        	width: "90%",
        	modal: true,
        	show: "clip",
        	hide: "clip",
        	buttons: {
	            "<{$smarty.const._SUBMIT}>": function() {
	            	var dlg = $(this);
	            	if(!xoopsFormValidate_addcontact()) return false;
					$.ajax({
						url: $("#addcontact").attr('action'),
						type: "POST",
						data: {contact_title: $("#contact_title").val(),
								contact_name: $("#contact_name").val(),
								contact_mail: $("#contact_mail").val(),
								contact_phone: $("#contact_phone").val(),
								contact_body: $("#contact_body_tarea").val(),
								icmscaptcha: $("#icmscaptcha").val(),
								op: $("#op").val()},
						dataType: "json",
						success: function(response) {
									if(response.status === "success") {
										document.forms.addcontact.reset();
										dlg.dialog("close");
										$('#form_message').html(response.message);
										$('#form_message').dialog('open');
									} else if(response.status === "error") {
										$("#form_error").html("<{$smarty.const._MD_PORTFOLIO_FAILURE}>: " + response.message);
									}
						},
					});
				},
				"<{$smarty.const._CANCEL}>" : function() {
					document.forms.addcontact.reset();
					$(this).dialog("close");
				}
			},
			Cancel: function() {
				document.forms.addcontact.reset();
				$(this).dialog( "close" );
			}
       });
       
       $(".contact_link").click(function(e) {
			e.preventDefault();
			$("#portfolio_form").dialog("open");
		});
		
		$("#form_message").dialog({
			autoOpen: false,
        	height: 200,
        	width: "90%",
        	modal: true,
        	show: "clip",
        	hide: "clip",
        	buttons: {
        		"OK": function() {
					$(this).dialog("close");
				}
        	}
		});
	});
</script>